package x.zero.controller.sys;




import x.zero.annotation.SysLog;
import x.zero.pojo.entity.SysJobLog;
import x.zero.service.sys.SysJobLogService;
import x.zero.util.CommonResult;
import x.zero.util.ValidatorUtils;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

/**
 * <p>
 * 定时任务调度日志表 前端控制器
 * </p>
 */
@Slf4j
@RestController
@RequestMapping("/sys/adminSysJobLog")
public class SysJobLogController {

    @Autowired
    private SysJobLogService adminSysJobService;

    @SysLog(MODULE = "cms", REMARK = "根据条件查询所有定时器日志表列表")
    @ApiOperation("根据条件查询所有定时器日志表列表")
    @GetMapping(value = "/list")

    public Object getAdminSysJobLogByPage(SysJobLog entity,
                                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        try {
            return CommonResult.success(adminSysJobService.page(pageNum,pageSize,entity));
        } catch (Exception e) {
            log.error("根据条件查询所有定时器日志表列表：%s", e.getMessage(), e);
        }
        return CommonResult.failed();
    }

    @SysLog(MODULE = "cms", REMARK = "保存定时器日志表")
    @ApiOperation("保存定时器日志表")
    @PostMapping(value = "/create")

    public Object saveAdminSysJobLog(@RequestBody SysJobLog entity) {
        try {
            if (adminSysJobService.save(entity)) {
                return CommonResult.success();
            }
        } catch (Exception e) {
            log.error("保存定时器日志表：%s", e.getMessage(), e);
            return CommonResult.failed();
        }
        return CommonResult.failed();
    }

    @SysLog(MODULE = "cms", REMARK = "更新定时器日志表")
    @ApiOperation("更新定时器日志表")
    @PostMapping(value = "/update/{ids}")

    public Object updateAdminSysJobLog(@RequestBody SysJobLog entity) {
        try {
            if (adminSysJobService.updateById(entity)) {
                return CommonResult.success();
            }
        } catch (Exception e) {
            log.error("更新定时器日志表：%s", e.getMessage(), e);
            return CommonResult.failed();
        }
        return CommonResult.failed();
    }

    @SysLog(MODULE = "cms", REMARK = "删除定时器日志表")
    @ApiOperation("删除定时器日志表")
    @GetMapping(value = "/delete/{ids}")

    public Object deleteAdminSysJobLog(@ApiParam("定时器日志表id") @PathVariable Long id) {
        try {
            if (ValidatorUtils.empty(id)) {
                return CommonResult.paramFailed("定时器日志表id");
            }
            if (adminSysJobService.deleteById(id)) {
                return CommonResult.success();
            }
        } catch (Exception e) {
            log.error("删除定时器日志表：%s", e.getMessage(), e);
            return CommonResult.failed();
        }
        return CommonResult.failed();
    }

    @SysLog(MODULE = "cms", REMARK = "给定时器日志表分配定时器日志表")
    @ApiOperation("查询定时器日志表明细")
    @GetMapping(value = "/{id}")

    public Object getAdminSysJobLogById(@ApiParam("定时器日志表id") @PathVariable Long id) {
        try {
            if (ValidatorUtils.empty(id)) {
                return CommonResult.paramFailed("定时器日志表id");
            }
            SysJobLog coupon = adminSysJobService.queryById(id);
            return CommonResult.success(coupon);
        } catch (Exception e) {
            log.error("查询定时器日志表明细：%s", e.getMessage(), e);
            return CommonResult.failed();
        }

    }

    @ApiOperation(value = "批量删除定时器日志表")
    @RequestMapping(value = "/delete/batch", method = RequestMethod.GET)
    @ResponseBody
    @SysLog(MODULE = "pms", REMARK = "批量删除定时器日志表")

    public Object deleteBatch(@RequestParam("ids") List<Long> ids) {
        boolean count = adminSysJobService.deleteById(ids);
        if (count) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

}



